package com.hnucm.springboot.service;

import com.hnucm.springboot.dao.IdcardMapper;
import com.hnucm.springboot.dao.PersonMapper;
import com.hnucm.springboot.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class PersonServiceImpl implements PersonService{

    @Autowired
    PersonMapper personMapper;
    @Autowired
    IdcardMapper idcardMapper;
//    @Override
//    public List<Person> findAllPerson() {
//        return personMapper.findAllPerson();
//    }

   @Transactional
    @Override
    public int deletePersonById(Integer id,Integer idcardid) {
       idcardMapper.deleteIdcardById(idcardid);
       return personMapper.deletePersonById(id);
   }
    @Override
    public int addPerson(Person person) {
       int result1= idcardMapper.addIdcard(person.getIdcardid());
        int result2=  personMapper.addPerson(person);
        if(result2>0&&result1>0){
         return result1;}
        return 0;
    }

    @Override
    public int updatePerson(Person person) {
        return personMapper.updatePerson(person);
    }
    @Override
    public List<Person> findAllPerson(){
       return personMapper.findAllPersonOrders();
//        return personMapper.findAllPersonIdcard2();
    }
}
